package com.Mms.service;

import com.Mms.dao.*;
import com.Mms.model.*;
import com.Mms.untl.Decryption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class serviceBySaveImpl implements serviceBySave {


    @Autowired
    MuserMapper muserMapper;

    @Autowired
    MajorMapper majorMapper;

    @Autowired
    UinfoMapper uinfoMapper;

    @Autowired
    MinfoMapper minfoMapper;

    @Autowired
    AnymessageMapper anymessageMapper;



    @Override
    public Boolean saveByMuser(Muser muser) {
        muserMapper.insert(muser);
       Uinfo uinfo = Decryption.decryInfo(muser.getUstuno());
       System.out.println(uinfo.getMajor());//打印
        MajorExample majorExample = new MajorExample();
        MajorExample.Criteria criteria = majorExample.createCriteria();
        criteria.andMajornoEqualTo(uinfo.getMajor());
        List<Major> majorlist = majorMapper.selectByExample(majorExample);
        uinfo.setMajor(majorlist.get(0).getMajorname());
        uinfoMapper.insert(uinfo);
        return true;
    }

    @Override
    public Boolean saveByMinfo(Minfo minfo,String stuno) {
        muserMapper.updateBystnoAndappleMinfo(stuno);
        minfoMapper.insert(minfo);
        return true;
    }

    @Override
    public Boolean saveAnymessage(Anymessage anymessage) {
        anymessageMapper.insert(anymessage);
        return true;
    }

    @Override
    public Boolean updataMuser(String ustno,int flag) {
        if(flag==1) {
            muserMapper.updateBystno(ustno);
            return true;
        }else{
            muserMapper.updateBystnobyTwo(ustno);
            return true;
        }
    }


}
